package net.sf.window.scope.tl;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import net.sf.window.scope.WindowScope;

public class WindowScopeInput extends TagSupport 
{
	private static final long serialVersionUID = -1522204079657399406L;

	@Override
	public int doStartTag() throws JspException 
	{
		try 
		{
			JspWriter writer = pageContext.getOut();

			StringBuilder inputField = new StringBuilder(
					"<input type='hidden' name='")
					.append(WindowScope.WINDOW_SCOPE_NAME).append("'")
					.append(" id='").append(WindowScope.WINDOW_SCOPE_NAME)
					.append("'").append(" value='")
					.append(WindowScopeRegistry.getWindowScope()).append("'")
					.append(" />");

			writer.write(inputField.toString());
		}
		catch (Exception e) 
		{
			throw new JspException(e.getMessage(), e);
		}
		return EVAL_PAGE;
	}
}
